/*
 * DataDepositorView.java
 */
package datadepositor;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLDecoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import monash.med.crystallography.DatasetTools.DataDepositor.DataDepositor;
import monash.med.crystallography.DatasetTools.oai_dsMerge.oai_dsMerge;

/**
 * The application's main frame.
 */
public class DataDepositorView extends FrameView {

   public static void openURL(String url) {
      String osName = System.getProperty("os.name");
      try {
         if (osName.startsWith("Mac OS")) {
            Class fileMgr = Class.forName("com.apple.eio.FileManager");
            Method openURL = fileMgr.getDeclaredMethod("openURL",
               new Class[] {String.class});
            openURL.invoke(null, new Object[] {url});
            }
         else if (osName.startsWith("Windows"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
         else { //assume Unix or Linux
            String[] browsers = {
               "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
            String browser = null;
            for (int count = 0; count < browsers.length && browser == null; count++)
               if (Runtime.getRuntime().exec(
                     new String[] {"which", browsers[count]}).waitFor() == 0)
                  browser = browsers[count];
            if (browser == null)
               throw new Exception("Could not find web browser");
            else
               Runtime.getRuntime().exec(new String[] {browser, url});
            }
         }
      catch (Exception e) {
         
         }
      }    
    
     public String locate() throws ClassNotFoundException, UnsupportedEncodingException {

        final URL location;
        final String classLocation = this.getClass().getName().replace('.', '/') + ".class";
        final ClassLoader loader = this.getClass().getClassLoader();
        if( loader == null )
        {
          location = ClassLoader.getSystemResource(classLocation);
        }
        else
        {
          location = loader.getResource(classLocation);
        }
        if( location != null ) 
        {
          Pattern p = Pattern.compile( "^.*:(.*)!.*$" ) ;

          Matcher m = p.matcher( URLDecoder.decode(location.getPath(), "UTF-8") );
          if( m.find() )
            return new File(m.group( 1 )).getParent();
          else
            throw new ClassNotFoundException( "Cannot parse location of '" + location + "'.  Probably not loaded from a Jar" ) ;
        }
        else 
          throw new ClassNotFoundException( "Cannot find class '" + this.getClass().getName() + " using the classloader" ) ;
  }          
    
    public DataDepositorView(SingleFrameApplication app) {
        super(app);

        initComponents();
        
        try{
        String resource = locate();
        
        String strMETSPath = resource + File.separator + "Example" + File.separator + "2NW0.xml"; 
        String strUploadPath = resource + File.separator + "Example" + File.separator + "Upload";
        
        txtMETSpath.setText(strMETSPath); 
        txtUploadPath.setText(strUploadPath);        
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        
        System.setOut( new PrintStream(
        new ConsoleView(txtConsoleView, System.out), true));        

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);

                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = DataDepositorApp.getApplication().getMainFrame();
            aboutBox = new DataDepositorAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        DataDepositorApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtRepositoryURL = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtRepositoryUsername = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtMETSpath = new javax.swing.JTextField();
        btnMETS = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        txtUploadPath = new javax.swing.JTextField();
        btnUpload = new javax.swing.JButton();
        btnGo = new javax.swing.JButton();
        txtRepositoryPassword = new javax.swing.JPasswordField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtConsoleView = new javax.swing.JTextArea();
        menuBar = new javax.swing.JMenuBar();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(datadepositor.DataDepositorApp.class).getContext().getResourceMap(DataDepositorView.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        txtRepositoryURL.setText(resourceMap.getString("txtRepositoryURL.text")); // NOI18N
        txtRepositoryURL.setName("txtRepositoryURL"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        txtRepositoryUsername.setText(resourceMap.getString("txtRepositoryUsername.text")); // NOI18N
        txtRepositoryUsername.setName("txtRepositoryUsername"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        txtMETSpath.setText(resourceMap.getString("txtMETSpath.text")); // NOI18N
        txtMETSpath.setName("txtMETSpath"); // NOI18N

        btnMETS.setText(resourceMap.getString("btnMETS.text")); // NOI18N
        btnMETS.setName("btnMETS"); // NOI18N
        btnMETS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionMETSBrowse(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        txtUploadPath.setText(resourceMap.getString("txtUploadPath.text")); // NOI18N
        txtUploadPath.setName("txtUploadPath"); // NOI18N

        btnUpload.setText(resourceMap.getString("btnUpload.text")); // NOI18N
        btnUpload.setName("btnUpload"); // NOI18N
        btnUpload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionUploadBrowse(evt);
            }
        });

        btnGo.setText(resourceMap.getString("btnGo.text")); // NOI18N
        btnGo.setName("btnGo"); // NOI18N
        btnGo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionGo(evt);
            }
        });

        txtRepositoryPassword.setText(resourceMap.getString("txtRepositoryPassword.text")); // NOI18N
        txtRepositoryPassword.setName("txtRepositoryPassword"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txtConsoleView.setColumns(20);
        txtConsoleView.setEditable(false);
        txtConsoleView.setLineWrap(true);
        txtConsoleView.setRows(5);
        txtConsoleView.setText(resourceMap.getString("txtConsoleView.text")); // NOI18N
        txtConsoleView.setWrapStyleWord(true);
        txtConsoleView.setName("txtConsoleView"); // NOI18N
        jScrollPane1.setViewportView(txtConsoleView);

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                    .add(mainPanelLayout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtRepositoryUsername, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel3)
                        .add(18, 18, 18)
                        .add(txtRepositoryPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(83, 83, 83))
                    .add(mainPanelLayout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(txtRepositoryURL, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(mainPanelLayout.createSequentialGroup()
                                .add(jLabel5)
                                .add(293, 293, 293))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
                                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, txtUploadPath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel4)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, txtMETSpath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, btnGo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, btnMETS, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, btnUpload, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(txtRepositoryURL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(txtRepositoryUsername, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3)
                    .add(txtRepositoryPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel4)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtMETSpath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnMETS))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel5)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtUploadPath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnUpload))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(btnGo)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 676, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(statusMessageLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 331, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 149, Short.MAX_VALUE)
                .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelLayout.createSequentialGroup()
                .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(statusAnimationLabel)
                    .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(statusMessageLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents
    private void actionMETSBrowse(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionMETSBrowse
        if (evt.getSource() == btnMETS) {
            int returnVal = fc.showOpenDialog(mainPanel);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                txtMETSpath.setText(file.getAbsolutePath());
            //This is where a real application would open the file.
            //log.append("Opening: " + file.getName() + "." + newline);
            } else {
            // log.append("Open command cancelled by user." + newline);
            }
        }
    }//GEN-LAST:event_actionMETSBrowse

    private void actionUploadBrowse(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionUploadBrowse
        if (evt.getSource() == btnUpload) {
            fco.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = fco.showOpenDialog(mainPanel);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fco.getSelectedFile();
                txtUploadPath.setText(file.getAbsolutePath());
            //This is where a real application would open the file.
            //log.append("Opening: " + file.getName() + "." + newline);
            } else {
            // log.append("Open command cancelled by user." + newline);
            }
        }
    }//GEN-LAST:event_actionUploadBrowse

    private void actionGo(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionGo

        Thread worker = new Thread( new HardWorker() );
        worker.setDaemon(true);
        worker.start();
    }//GEN-LAST:event_actionGo

    private void go() {
        if(validateGo())
        {
            btnUpload.setEnabled(false);
            int n = JOptionPane.showConfirmDialog(
    mainPanel,
    "WARNING: By clicking 'Yes', you understand that your project data\n" +
                    "may be made publically accessible, depending on the\n" +
                    "target repository specified.",
    "Confirm Project Upload",
    JOptionPane.YES_NO_OPTION);
            
            if(n == 0)
            {
                txtConsoleView.setText("");
                
                oai_dsMerge oaiM = new oai_dsMerge(txtUploadPath.getText());
                oaiM.writeOai_ds(new File(txtUploadPath.getText()).getAbsolutePath()
                        + File.separator + "oai_ds.xml");

                String OBJID = DataDepositor.DepositData(txtRepositoryURL.getText(),
                        txtRepositoryUsername.getText(),
                        String.valueOf(txtRepositoryPassword.getPassword()),
                        txtMETSpath.getText(),
                        txtUploadPath.getText());

                String strUrl = "";

                if(txtRepositoryURL.getText().endsWith("/"))
                {
                    strUrl = txtRepositoryURL.getText().substring(0, txtRepositoryURL.getText().length()-1);
                }
                else
                {
                    strUrl = txtRepositoryURL.getText();
                }

                String objectURL = strUrl + "/get/" + OBJID;

                System.out.println("\nProject URL:\n" + objectURL);

                openURL(objectURL);

            }
            
            btnUpload.setEnabled(true);  
        }
    }
    
    private boolean validateGo()
    {

        try {     
            if(txtRepositoryURL.getText().equals(""))
            {
                throw new Exception("Missing repository URL");
            } 
            else if(txtRepositoryUsername.getText().equals(""))
            {
                throw new Exception("Missing repository Username path");
            }         
            else if(!new File(txtMETSpath.getText()).exists())
            {
                throw new Exception("Invalid METS file path");
            }
            else if(!new File(txtUploadPath.getText()).exists())
            {
                throw new Exception("Invalid upload path");
            }
        }
        catch (Exception e)
        {
            JOptionPane.showMessageDialog(mainPanel, e.getMessage(),
				                       "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }         

        return true;
  
    }      
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGo;
    private javax.swing.JButton btnMETS;
    private javax.swing.JButton btnUpload;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextArea txtConsoleView;
    private javax.swing.JTextField txtMETSpath;
    private javax.swing.JPasswordField txtRepositoryPassword;
    private javax.swing.JTextField txtRepositoryURL;
    private javax.swing.JTextField txtRepositoryUsername;
    private javax.swing.JTextField txtUploadPath;
    // End of variables declaration//GEN-END:variables
    final JFileChooser fc = new JFileChooser();
    final JFileChooser fco = new JFileChooser();
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;

    private final class HardWorker implements Runnable {

        public void run() {
            //simulateLongDelay();
            try {
                // do stuff here
                go();
            //EventQueue.invokeLater( new GuiUpdater(quotes) );
            } catch (Exception ex) {
            //EventQueue.invokeLater( new GuiUpdater(ex) );
            }
        }
    }
}
